package wh.ispct



import grails.test.mixin.*
import org.junit.*
import wh.ispct.util.ExtTreeData
import wh.ispct.util.ExtTreeNode

/**
 * See the API for {@link grails.test.mixin.domain.DomainClassUnitTestMixin} for usage instructions
 */
@TestFor(Menu)
class MenuTests {

    void testSomething() {
       fail "Implement me"
    }
	
	void testTree(){
	 	List<Menu> menuList = Menu.findAll()
		 println menuList
		ExtTreeData<Menu> treeData = new ExtTreeData<Menu>()
		treeData.addNodes(menuList,{
			it ->
			def m = it
			def parentId = m.parentMenu==null ? null : m.parentMenu.id.toString()
			ExtTreeNode node = new ExtTreeNode(m.id.toString(),parentId,m.name,m.type,false)
			node.putAt("sort", m.sort)
			node.putAt("singleContent", m.singleContent)
			return node
		})
		
		println treeData.getRoots()
		
		treeData.visit {it ->
			println it.name
		}
	}
	
	void testFind(){
		println Menu.findByName("123")
		
	}
}
